/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package basededatos;

/**
 *
 * @author Sarazua
 */
import java.awt.Container;
import java.awt.GridBagLayout;
import java.sql.*;
import java.util.Scanner;
import javax.swing.Box;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

public class Main {

    private static javax.swing.JFrame Frame1;
    private static javax.swing.JPanel Panel;

    public Main() {
    }

    public static void main(String[] args) {        
        GUI();
        conexion();
    }

    public static void conexion(){
        String driver, user, pass, direccion;
        Scanner scan = new Scanner(System.in);
        try {
            driver = "org.postgresql.Driver";
            user = "postgres";
            pass = "postgres";
            direccion = "jdbc:postgresql://localhost:5432/proy1/";

            Class.forName(driver);
            Connection conexion = DriverManager.getConnection(direccion, user, pass);
            System.out.println("Conexion realizar con exito");
//            System.out.println("1 Actualizacion, Eliminacion, Creacion");
//            System.out.println("2 Select:");
//            Integer opcion = scan.nextInt();
//            if (opcion == 2) {
                System.out.println("Ingrese Instruccion ");
                String instruccion = scan.nextLine();
                Statement inst = conexion.createStatement();
                ResultSet rs;
                // * Select getCargas (1)
                String querry = instruccion;
                rs = inst.executeQuery(querry);

//                JTable tabla;
//                DefaultTableModel modelo;
//                tabla.setmodel(modelo);

                while (rs.next()) {
                    System.out.println("nombre: "+rs.getString("Nombre"));
                }
                inst.execute("END");
                inst.close();
//            } else if (opcion == 1) {
//                System.out.println("Ingrese Instruccion ");
//                String instruccion = scan.nextLine();
//                Statement inst = conexion.createStatement();
//                ResultSet rs;
//                // * Select CrearCuenta (1, 'Jose')
//                // * Select RegistrarCargas (2,'2004-10-19 10:23:54', 1.3, true, 'exportacion' , true, 1, 1)
//                String querry = instruccion;
//                rs = inst.executeQuery(querry);
//                inst.execute("END");
//                inst.close();
//            }
            conexion.close();
        } catch (Exception e) {
            System.out.println("No se pudo realizar la Conexion");
            e.printStackTrace();
        }
    }
    public static void GUI() {
//        Frame1 = new javax.swing.JFrame("Menu");
//        Frame1.setSize(2000,2000);
//        Box c = Box.createHorizontalBox();
//        c.add(new JLabel ("Serlipsa"));
//        Box a = Box.createHorizontalBox();
//        a.add(new JLabel ("AKI"));
//        //a.add(new JTabbedPane());
//        Frame1.getContentPane().add(c);
//        Frame1.getContentPane().add(a);
//        Frame1.setVisible(true);
        getContentPane().setLayout(new GridBagLayout());


    }

}
